#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <functional>
#include "File/File.h"
#include "FoundationTest.h"

using namespace SystemTool;

static void LogFile(std::string strMsg)
{
    std::string strFilePath = "/Users/tangyingzhong/Desktop/12.log";
    std::fstream os(strFilePath,std::ios::app | std::ios::out);
    os << strMsg << "\n";
    os.close();
}

uint64_t g_iTotalSize = 0;
void Progress(uint64_t iSize)
{
    int iPercent = iSize * 100.0 / g_iTotalSize;
    std::cout << "Percent:" << iPercent << "%" << "  iSize=" << iSize << "  TotalSize=" << g_iTotalSize << std::endl;
}

void FoundationTest()
{
    // g_iTotalSize = 1188556280;
    // std::string strMovieFilePath = "/Users/tangyingzhong/Downloads/qt5.7.0.exe";
    // std::ifstream is(strMovieFilePath, std::ios::in | std::ios::binary);

    // std::string strOutFilePath = "/Users/tangyingzhong/Downloads/qt.exe";
    // std::ofstream os(strOutFilePath, std::ios::out | std::ios::binary);

    // SystemTool::Foundation::CopyStream(is, os, 8192, Progress);

    // g_iTotalSize = 523719884;
    // std::string strMovieFilePath2 = "/Users/tangyingzhong/Downloads/林俊杰.wav";
    // std::ifstream is(strMovieFilePath2, std::ios::in | std::ios::binary);

    // std::string strOutFilePath2 = "/Users/tangyingzhong/Downloads/12.wav";
    // std::ofstream os(strOutFilePath2, std::ios::out | std::ios::binary);

    // SystemTool::Foundation::CopyStream64(is, os, 512, Progress);

    // std::vector<unsigned char> vByteArr;
    // vByteArr.push_back(0x32);
    // vByteArr.push_back(0x22);
    // vByteArr.push_back(0x12);
    // vByteArr.push_back(0x02);
    // std::string strData = SystemTool::Foundation::ToHexString(vByteArr);
    // std::cout << strData << std::endl;

    // std::vector<unsigned char> vNewByteArr;
    // if (!SystemTool::Foundation::FromHexString(strData, vNewByteArr))
    // {
    //     std::cout << "Failed to trans to hex data from string\n";
    // }
    // LogFile("Pause");
    // for (size_t index = 0; index < vNewByteArr.size(); index++)
    // {
    //     char str[3] = {0};
    //     sprintf(str, "%02X", vNewByteArr[index]);
    //     std::string strData = str;
    //     std::cout << strData << std::endl;
    // }

    // std::string strSrcData = "符合丹江口市分fhjsdhfjsk";
    // std::string strBase64Data = SystemTool::Foundation::ToBase64(strSrcData);
    // std::cout << strBase64Data << std::endl;

    // std::string strSrcData2 = SystemTool::Foundation::FromBase64(strBase64Data);
    // std::cout << strSrcData2 << std::endl;
    // if(strSrcData2 == strSrcData)
    // {
    //     std::cout << "Same\n";
    // }
    // else
    // {
    //     std::cout << "Not Same\n";
    // }
    // LogFile("Pause");

    
    // std::string strInFilePath = "/Users/tangyingzhong/Downloads/林俊杰.wav";
    // g_iTotalSize = SystemTool::File::GetSize(strInFilePath);
    // std::string strOutFilePath = "/Users/tangyingzhong/Downloads/base64.wav";
    // std::ifstream is(strInFilePath, std::ios::in | std::ios::binary);
    // std::ofstream os(strOutFilePath, std::ios::out | std::ios::binary);
    // if (!SystemTool::Foundation::ToBase64(is, os, false, 8192, Progress))
    // {
    //     std::cout << "Failed to base64 file\n";
    // }

    // std::string strInFilePath2 = "/Users/tangyingzhong/Downloads/base64.wav";
    // g_iTotalSize = SystemTool::File::GetSize(strInFilePath2);
    // std::string strOutFilePath2 = "/Users/tangyingzhong/Downloads/林俊杰2.wav";
    // std::ifstream is2(strInFilePath2, std::ios::in | std::ios::binary);
    // std::ofstream os2(strOutFilePath2, std::ios::out | std::ios::binary);
    // if (!SystemTool::Foundation::FromBase64(is2, os2, 8192, Progress))
    // {
    //     std::cout << "Failed to parse base64 file\n";
    // }
    // LogFile("Pause");

    std::istringstream is("fksdjhfklsdhflksahfslk倒海翻江可视电话各方尽快释放iu");
    std::string strData = "";
    SystemTool::Foundation::CopyToString64(is, strData);
    if(strData == is.str())
    {
        std::cout << "Same!\n";
    }
    else
    {
        std::cout << "Not Same!\n";
    }
}
